
# Standard Python 2.5 library
import os
import os.path
import sys
import time

from xml.etree.ElementTree import parse

#------------------------------------------------------------------------------

xml_files = [filename for filename in os.listdir("xml")
                      if filename != ".svn"]
results = {}

for file in xml_files:
    times = []
    for i in range(5): # keep best of 5 timings
        path = os.path.join("xml", file)
        tic = time.time()
        parse(path)
        toc = time.time()
        times.append(toc-tic)
    results[file] = min(times)

platform = sys.platform
version = sys.version.split()[0]
print "ElementTree benchmark -- Python %s on %s" % (version, sys.platform)
for item in results.items():
    length = str(max(len(filename) for filename in results))
    format = "  %-" +  length + "s: %.5f s"
    print  format % item
